package org.whatever.aha.zjut.platform.mapper.project;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.whatever.aha.zjut.platform.entity.project.ProjectMember;
import org.whatever.aha.zjut.platform.vo.project.ProjectMemberVo;

import java.util.List;
import java.util.Set;

/**
 * @author Vc
 * @version 1.0
 * @Desc
 * @date 2021/09/14 23:53
 */
public interface ProjectMemberMapper extends BaseMapper<ProjectMember> {
    @Select("select * from project_member where project_id = #{project_id} order by project_member_rank")
    List<ProjectMemberVo> getProjectMembersById(@Param("comp_id")int compId);

    @Select("select * from project_member where member_id = #{userId} and project_id = #{projectId}")
    ProjectMemberVo getProjectMemberVoById(@Param("userId")int userId, @Param("projectId")int projectId);

    @Select("<script>"
            +"select member_info.project_id from "
            +"(select distinct project_id from project_member where member_id = #{memberId}) member_info "
            +"left join "
            +"(select project_id,comp_id from project) project_info "
            +"on project_info.project_id = member_info.project_id "
            +"inner join "
            +"(select comp_id from competition where 1=1 "
            +"<if test='compType != null'>"
            +"and comp_type = #{compType}"
            +"</if>"
            +"<if test='compStatus != null'>"
            +"and comp_status = #{compStatus}"
            +"</if>"
            +"<if test='compYear != null'>"
            +"and comp_year = #{compYear}"
            +"</if>"
            +" ) competition_info "
            +"on project_info.comp_id = competition_info.comp_id "
            +"order by member_info.project_id DESC "
            +"</script>")
    Set<Integer> getProjectIdByMemberIdConditional(@Param("memberId")int memberId, @Param("compType")Integer compType, @Param("compStatus")Integer compStatus, @Param("compYear")Integer compYear);
}



